package com.store.app.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.store.app.ExitApplication;
import com.store.app.R;
import com.store.app.adapter.BookedViewPagerAdapter;
import com.store.app.fragment.TheGuideAgreeFragment;
import com.store.app.fragment.TheGuideNewFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/2/9.
 */
public class GuideShoppingActivity extends FragmentActivity implements View.OnClickListener {
    public List<Fragment> fragments = new ArrayList<Fragment>();
    private TextView radioGroup_titlebar_2, radioGroup_titlebar_3;
    private TextView title;
    private ViewPager viewpager;
    private String showFragmentIndex = "0";

    private TextView tv2;
    private TextView tv3;


    private TextView tv_Right1;
    private ImageView public_ll_return;
    private LinearLayout ll_invitation_members;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ExitApplication.getInstance().addActivity(this);
        setContentView(R.layout.activity_guide_shopping);
        initView();
        initData();
    }

    private void initView() {
        viewpager = (ViewPager) findViewById(R.id.booked_viewpager);
        tv_Right1 = (TextView) findViewById(R.id.tv_right1);
        tv_Right1.setVisibility(View.VISIBLE);
        tv_Right1.setBackgroundResource(R.drawable.pic_icon_history);
        tv_Right1.setOnClickListener(this);
        tv2 = (TextView) findViewById(R.id.tv2);        //已同意
        tv3 = (TextView) findViewById(R.id.tv3);        //新申请
        title = (TextView) findViewById(R.id.tvTitle);
        title.setText("社区导购");
        tv2.setOnClickListener(this);
        tv3.setOnClickListener(this);
        public_ll_return = (ImageView) findViewById(R.id.public_ll_return);
        public_ll_return.setOnClickListener(this);
        ll_invitation_members = (LinearLayout) findViewById(R.id.ll_invitation_members);
        ll_invitation_members.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv2:
                showFragmentIndex = "0";
                refreshUITab(showFragmentIndex);
                viewpager.setCurrentItem(0);
                break;
            case R.id.tv3:
                showFragmentIndex = "1";
                refreshUITab(showFragmentIndex);
                viewpager.setCurrentItem(1);
                break;
            case R.id.public_ll_return:
                finish();
                break;
            case R.id.ll_invitation_members:
                Intent intent = new Intent(GuideShoppingActivity.this,InvitationMemberActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_right1:
                Intent intent1 = new Intent(GuideShoppingActivity.this,HistoryActivity.class);
                startActivity(intent1);
                break;
        }
    }

    private void refreshUITab(String index) {
        if (index.equals("0")) {
            tv2.setTextColor(Color.parseColor("#f96116"));
            tv3.setTextColor(Color.parseColor("#333333"));
        } else if (index.equals("1")) {
            tv3.setTextColor(Color.parseColor("#f96116"));
            tv2.setTextColor(Color.parseColor("#333333"));
        }
    }

    private void initData() {
        fragments.add(new TheGuideAgreeFragment());
        fragments.add(new TheGuideNewFragment());
        BookedViewPagerAdapter disfratab = new BookedViewPagerAdapter(getSupportFragmentManager(), viewpager, fragments);
        viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                refreshUITab(position + "");
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        refreshUITab(showFragmentIndex);
    }
}
